home *** CD-ROM | disk | FTP | other *** search
/ Programming in Microsoft Windows with C# / Programacion en Microsoft Windows con C#.iso / Original Code / Files and Streams / WildCardHexDump / WildCardHexDump.cs next >
Encoding:
Text File  |  2001-01-15  |  1.5 KB  |  54 lines

  1. //----------------------------------------------
  2. // WildCardHexDump.cs ⌐ 2001 by Charles Petzold
  3. //----------------------------------------------
  4. using System;
  5. using System.IO;
  6.  
  7. class WildCardHexDump: HexDump
  8. {
  9.      public new static int Main(string[] astrArgs)
  10.      {
  11.           if (astrArgs.Length == 0)
  12.           {
  13.                Console.WriteLine("Syntax: WildCardHexDump file1 file2 ...");
  14.                return 1;
  15.           }
  16.           foreach (string str in astrArgs)
  17.                ExpandWildCard(str);
  18.  
  19.           return 0;
  20.      }
  21.      static void ExpandWildCard(string strWildCard)
  22.      {
  23.           string[] astrFiles; 
  24.  
  25.           try
  26.           {
  27.                astrFiles = Directory.GetFiles(strWildCard);
  28.           }
  29.           catch 
  30.           {
  31.                try
  32.                {
  33.                     string strDir  = Path.GetDirectoryName(strWildCard);
  34.                     string strFile = Path.GetFileName(strWildCard);
  35.  
  36.                     if (strDir == null || strDir.Length == 0)
  37.                          strDir = ".";
  38.  
  39.                     astrFiles = Directory.GetFiles(strDir, strFile);
  40.                }
  41.                catch
  42.                {
  43.                     Console.WriteLine(strWildCard + ": No Files found!");
  44.                     return;
  45.                }
  46.           }
  47.           if (astrFiles.Length == 0)
  48.                Console.WriteLine(strWildCard + ": No files found!");
  49.  
  50.           foreach(string strFile in astrFiles)
  51.                DumpFile(strFile);
  52.      }
  53. }
  54.